package com.ervanalb.cellradio.shared;

import java.nio.ByteBuffer;

/**
 * Implements a list of clients, identified by their channel numbers. Includes
 * serialization routines.
 * 
 * @author eric
 */
public class ClientList {
	public int[] clients;

	public ClientList(ByteBuffer bb) {
		int len = bb.getInt();
		clients = new int[len];
		for (int i = 0; i < clients.length; i++)
			clients[i] = bb.getInt();
	}

	public int size() {
		return 4 + 4 * clients.length;
	}

	public ByteBuffer pack() {
		ByteBuffer bb = ByteBuffer.allocate(size());
		bb.putInt(clients.length);
		for (int i = 0; i < clients.length; i++)
			bb.putInt(clients[i]);
		bb.rewind();
		return bb;
	}
}
